#pragma once
#include "../base/basic_types.h"
#include "texture.h"

typedef void* HW_BufferPtr;

enum KPrimType {eTriangleStrip = 0, eTriangleList, eLineStrip, eLineList};

struct KRenderState
{
	enum KBlendMode {eDisableBlend, eAlphaBlend, eAddBlend};
	
	KColor mModulateColor;
	KTexture* mTexture;
	KBlendMode mBlendMode;

	KRenderState() {
		mModulateColor = 0xffffffff;
		mTexture = NULL;
		mBlendMode = eDisableBlend;
	}
};

struct KSpriteRect
{
	int sx, sy;   // offset on the texture map(in texels)
	int w, h;     // size in texels	
	float cx, cy; // center offset
};

struct KDrawLocal
{
	float x, y;
	KRotation rot;
};

class KDrawManager
{
public:
	// Call these two functions before and after the whole scene's rendering
	static void Begin();
	static void End();
	
	// Apply render state
	static void SetRenderState(const KRenderState& rs);

	// Functions to draw texture sprite.
	static void DrawSprite(const KDrawLocal& local, KTexture* pTexture, const KSpriteRect& rect, KColor color);

	// Functions to draw immediate data
	static void Draw_P (const VERTEX_P*  pData, const KDrawLocal& local, KPrimType type, unsigned int vertCnt);
	static void Draw_PC(const VERTEX_PC* pData, const KDrawLocal& local, KPrimType type, unsigned int vertCnt);
	static void Draw_PT(const VERTEX_PT* pData, const KDrawLocal& local, KPrimType type, unsigned int vertCnt);

	// Functions to create and draw hardware buffers
	static HW_BufferPtr		CreateHWBuffer(const VERTEX_P*  pData, KPrimType type, unsigned int vertCnt);
	static HW_BufferPtr		CreateHWBuffer(const VERTEX_PC* pData, KPrimType type, unsigned int vertCnt);
	static HW_BufferPtr		CreateHWBuffer(const VERTEX_PT* pData, KPrimType type, unsigned int vertCnt);
	static void				DeleteHWBuffer(HW_BufferPtr pBuffer);
	static void				Draw_HWBuf(const KDrawLocal& local, HW_BufferPtr pBuffer);

	// Functions to config camera views
	static void SetupView(float w, float h, const KVec2& center, KColor bgClr);

	static void GetViewportSize(unsigned int& width, unsigned int& height);

};